package com.wyr.common.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SaToken拦截配置
 *
 * @author wangyiren
 * @version 1.0
 * &#064;title SaTokenConfigure
 * &#064;description
 * &#064;date 2025/03/06 14:44
 */
@Slf4j
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    /**
     * 注册拦截器
     *
     * @param registry
     * &#064;description
     * @return: void
     * @author wangyiren
     * &#064;date 2025/5/8 10:39
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                // swagger
                .excludePathPatterns("/v3/**", "/doc.html/**", "/static/**", "/swagger-ui.html", "/webjars/**")
                .excludePathPatterns("/user/doLogin");
    }
}
